//
//  HZHeadLoginView.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZHeadLoginView.h"

#import "UIViewController+MMDrawerController.h"


@interface HZHeadLoginView()

@property(nonatomic,strong)UIView*  ownView;
@property(nonatomic,strong)UIImageView*  headImg;
@property(nonatomic,strong)UIButton*  loginBtn;
@property(nonatomic,strong)UIButton*  registerBtn;

@end

@implementation HZHeadLoginView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置并添加子控件
        [self setupUI];
    }
    return self;
}

#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{
    
    //设置背景色
    self.backgroundColor = [UIColor whiteColor];
    
    //添加
     [self addSubview:self.ownView];
    [self.ownView addSubview:self.headImg];
    [self.ownView addSubview:self.loginBtn];
    [self.ownView addSubview:self.registerBtn];
   
    
    [self.ownView makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.top.equalTo(self);
        make.height.equalTo(100);
    }];
    
    //约束
    [self.headImg makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.top.equalTo(20);
    }];
    
    [self.loginBtn makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.headImg.centerX).offset(-40);
        make.top.equalTo(self.headImg.bottom).offset(0);
    }];
    
    [self.registerBtn makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.headImg.centerX).offset(50);
        make.top.equalTo(self.headImg.bottom).offset(0);
    }];
    
}


#pragma mark -
#pragma mark     实现按钮点击方法
-(void)login{
    
    
    //发布按钮点击通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"login" object:self];
    

}

-(void)register{
    
    //发布按钮点击通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"register" object:self];
}


#pragma mark -
#pragma mark     懒加载子控件
-(UIView *)ownView{
    if (!_ownView) {
        
        _ownView = [[UIView alloc]init];
        _ownView.backgroundColor = [UIColor colorWithRed:46/255.0 green:179/255.0 blue:173/255.0 alpha:1];
    }
    return _ownView;
}


-(UIImageView *)headImg{
    if (!_headImg) {
        
        _headImg = [[UIImageView alloc]init];

        _headImg.image = [UIImage imageNamed:@"name"];
    }
    return _headImg;
}

-(UIButton *)loginBtn{
    if (!_loginBtn) {
        
        _loginBtn = [[UIButton alloc]init];
        
        //监听按钮点击
        [_loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
        
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        
    }
    return _loginBtn;
}


-(UIButton *)registerBtn{
    if (!_registerBtn) {
        
        _registerBtn = [[UIButton alloc]init];
        
        //监听按钮点击
        [_registerBtn addTarget:self action:@selector(register) forControlEvents:UIControlEventTouchUpInside];
        
        [_registerBtn setTitle:@"短信注册登录" forState:UIControlStateNormal];
        [_registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _registerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        
    }
    return _registerBtn;
}



@end
